package com.newzqxq.common.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

/**
 * Created by Administrator on 2017/6/30.
 */
public class DqkPayTools {
    // 获取一个订单当前应还款的总金额,罚息要写入数据库
    public static double getOrderRepayTotalMoney(double loan_amt,Date expired_time ){
        double total_money = 0.0;
        double overdue_fee = 0.0;
//        double loan_amt = (Double) map.get("loan_amt");

//        Date expired_time = new Date((Long) map.get("expired_time"));
        Date now = new Date();
        int overdue_days = DateUtils.daysOfTwo(expired_time,now);
        int hours = DateUtils.getHour(now);
        if(hours<18){
            //小于18点，不算一天
            overdue_days = overdue_days-1;
        }
        if(overdue_days>1) {
            overdue_fee = overdue_days * loan_amt * 0.02;
        }
        total_money = loan_amt + overdue_fee;// 只算逾期，服务费已经先扣了

        return total_money;
    }


    public static String risk_item_format(Map<String,Object> userinfo){
        String user_id=userinfo.get("user_id").toString();
        String phone =userinfo.get("telephone").toString();
        String time = DateUtils.dateToStr( new Date((long)userinfo.get("create_time")),DateUtils.DATE_FORMAT_DATETIMEMS);
        String full_name=userinfo.get("true_name").toString();
        String idcard = userinfo.get("idcard_no").toString();
        return risk_item_format(user_id,phone,time,full_name,idcard);
    }

    public static String risk_item_format(String user_id,String phone,String time,String full_name,String idcard){
        final String fmt = "{\"frms_ware_category\":\"2010\",\"user_info_mercht_userno\":\"%s\",\"user_info_bind_phone\":\"%s\",\"user_info_dt_register\":\"%s\",\"user_info_full_name\":\"%s\",\"user_info_id_type\":\"0\",\"user_info_id_no\":\"%s\",\"user_info_identify_type\":\"1\",\"user_info_identify_state\":\"1\"}";
        String ret =  String.format(fmt,user_id,phone,time,full_name,idcard);
        return ret;
    }

    public static String get_once_str_hour(){
        SimpleDateFormat df = new SimpleDateFormat("yyMMddHH");
        return  df.format(new Date());
    }
}
